package edu.cuc.nio.channel;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ChannelDemo01 {
    public static void main(String[] args) {
        try {
            File file = new File("test");
            FileOutputStream out = new FileOutputStream(file);
            FileChannel fileChannel = out.getChannel();
            String str = "akb48";
            ByteBuffer buf = ByteBuffer.allocate(1024);
            buf.put(str.getBytes());
            buf.flip();
            fileChannel.write(buf);
            fileChannel.close();
            out.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
